module.exports = class extends think.Model {
  /**
   * 获取分类数目
   */
  async getCategoriesNumber() {
    return this.where({type: 'category'}).count();
  }

  async getPostCategoriesByCid(cid) {
    const midList = await think.model('relationships').where({cid: cid}).getField('mid');
    if (think.isEmpty(midList)) {
      return [];
    }
    return await this.where({type: 'category', mid: ['in', midList]}).select();
  }
};
